home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / basic / mildred / mildred.lha / lha / MScreen.lha / MildredScreen.ascii < prev    next >
Text File  |  1999-03-07  |  9KB  |  283 lines

  1. WBStartup
  2.  
  3. DEFTYPE.w
  4. MCPU Processor
  5. Mc2pCPUmode Processor
  6.  
  7. *ScrVP._ViewPort=0
  8. IsAGA.b=False
  9. Dim PlanarBuf.l(2) ; Base address of planar memory to output c2p to (allowed up to triple buffers)
  10.  
  11. PrefDisplayID.l=$0 ; Default ModeID
  12. PrefDisplayWidth.w=320 ; Default Width
  13. PrefDisplayHeight.w=240 ; Default Height
  14. PrefDisplayBuffering.b=3 ; 1..3. 1=Singlebuffered, 2=Doublebuffered, 3=Triplebuffered
  15.  
  16. SMRMinX=320 ; Minimum width
  17. SMRMinY=240 ; Minimum height
  18. SMRMaxX=640 ; Maximum width
  19. SMRMaxY=480 ; Maximum height
  20.  
  21. ;Either include SMR.bb2, or set PrefDisplayID, Width and Height to valid numbers (read from a prefs file?)
  22. INCLUDE "SMR.bb2"
  23.  
  24. Function.b InitDisplay{Title$}
  25. ;Creates a display for AGA or Graphics-Card output
  26. ;Title$=The screen title (not displayed)
  27.   SHARED PrefDisplayWidth.w,PrefDisplayHeight.w,PrefDisplayBuffering.b
  28.   SHARED *ScrVP._ViewPort,PrefDisplayID.l,IsAGA.b,PlanarBuf()
  29.   ;Open a test screen first to a) test for AGA or GFX-Card, and b) because the dimensions might be
  30.   ;too large to open a chipram screen, and the dimensions for AGA have not yet been reduced to within limits
  31.   Dim ScrTags.TagItem(13)
  32.   Rect.Rectangle\MinX=0,0,320,240 ; For test
  33.   ScrTags(0)\ti_Tag=#SA_Width,320 ; For test
  34.   ScrTags(1)\ti_Tag=#SA_Height,240; For test
  35.   ScrTags(2)\ti_Tag=#SA_Depth,8
  36.   ScrTags(3)\ti_Tag=#SA_DisplayID,PrefDisplayID
  37.   ScrTags(4)\ti_Tag=#SA_Type,$F
  38.   ScrTags(5)\ti_Tag=#SA_Quiet,True
  39.   ScrTags(6)\ti_Tag=#SA_ShowTitle,False
  40.   ScrTags(7)\ti_Tag=#SA_Behind,True
  41.   ScrTags(8)\ti_Tag=#SA_DClip,&Rect ; For test
  42.   ScrTags(9)\ti_Tag=#SA_Exclusive,False
  43.   ScrTags(10)\ti_Tag=#SA_Draggable,True
  44.   ScrTags(11)\ti_Tag=#SA_AutoScroll,False
  45.   ScrTags(12)\ti_Tag=#TAG_DONE,0
  46.   ScrTags(13)\ti_Tag=#TAG_DONE,0
  47.   UsedChip.l=((320 LSR 3)*240)*8 ; With test params (depth 8)
  48.   FreeChip.l=AvailMem_(#MEMF_CHIP)
  49.   Forbid_
  50.   If ScreenTags(0,Title$,&ScrTags(0))<>0 ; Test for GFX-Card or AGA
  51.     NowChip.l=AvailMem_(#MEMF_CHIP)
  52.     Permit_
  53.     If FreeChip-NowChip<UsedChip
  54.       ; Graphics card screen
  55.       IsAGA=False
  56.       PrefDisplayWidth AND $FFF0 ; For gfx-cards, width to nearest 16
  57.       ScrTags(0)\ti_Tag=#SA_Width,PrefDisplayWidth
  58.       Rect.Rectangle\MinX=0,0,PrefDisplayWidth,PrefDisplayHeight
  59.       ScrTags(1)\ti_Tag=#SA_Height,PrefDisplayHeight*PrefDisplayBuffering
  60.       ScrTags(8)\ti_Tag=#SA_DClip,&Rect
  61.       VWait 5 ; seems to be necessary (safer)
  62.       Free Screen 0
  63.       VWait 5
  64.       If ScreenTags(0,Title$,&ScrTags(0))<>0
  65.         For Loop.w=0 To PrefDisplayBuffering-1
  66.           If Loop=0 Then WFlags.l=$1900 Else WFlags.l=$800
  67. If Window(Loop,0,PrefDisplayHeight*Loop,PrefDisplayWidth,PrefDisplayHeight,WFlags,"",0,0)=0 Then Function Return False
  68.           Menus Off
  69.           ScreensBitMap 0,Loop
  70.           *TmpBmp.bitmap=Addr BitMap(Loop)
  71.           Offset.l=*TmpBmp\_ebwidth*(PrefDisplayHeight*Loop)
  72.           For DLoop.w=0 To 8-1 ; Depth of 8
  73.             *TmpBmp\_data[DLoop]=*TmpBmp\_data[DLoop]+Offset
  74.           Next DLoop
  75.         Next Loop
  76.       Else
  77.         Function Return False
  78.       EndIf
  79.     Else
  80.       ; AGA screen
  81.       IsAGA=True
  82.       PrefDisplayWidth AND $FFC0 ; For AGA, width to nearest 64
  83.       ScrTags(0)\ti_Tag=#SA_Width,PrefDisplayWidth
  84.       Rect.Rectangle\MinX=0,0,PrefDisplayWidth,PrefDisplayHeight
  85.       ScrTags(1)\ti_Tag=#SA_Height,PrefDisplayHeight ; Seperate buffers
  86.       ScrTags(8)\ti_Tag=#SA_DClip,&Rect
  87.       ScrTags(3)\ti_Tag=#SA_DisplayID,PrefDisplayID
  88.       Forbid_
  89.       VWait 5 ; seems to be necessary (safer)
  90.       Free Screen 0
  91.       VWait 5
  92.       For Loop.w=0 To PrefDisplayBuffering-1
  93.         If Loop=0 Then WFlags.l=$1900 Else WFlags.l=$800
  94.         If AvailMem_(#MEMF_CHIP)>=(PrefDisplayWidth*PrefDisplayHeight)+16
  95.           Memory.l=AllocMem((PrefDisplayWidth*PrefDisplayHeight)+16,$10002) ; Chip bitmap
  96.           Memory=(Memory+16) AND $FFFFFFF0 ; Align for move16's
  97.           If Memory<>0
  98.             CludgeBitMap Loop,PrefDisplayWidth,PrefDisplayHeight,8,Memory ; Depth 8
  99.             If Loop=0
  100.               ScrTags(12)\ti_Tag=#SA_BitMap,Addr BitMap(0)
  101.               If ScreenTags(0,Title$,&ScrTags(0))=0
  102.                 Permit_
  103.                 Function Return False
  104.               EndIf
  105.             EndIf
  106. If Window(Loop,0,0,PrefDisplayWidth,PrefDisplayHeight,WFlags,"",0,0)=0 Then Function Return False
  107.             Menus Off
  108.           Else
  109.             Permit_
  110.             Function Return False
  111.           EndIf
  112.         Else
  113.           Permit_
  114.           Function Return False
  115.         EndIf
  116.         PlanarBuf(Loop)=Memory
  117.       Next Loop
  118.       Permit_
  119.     EndIf
  120.     DEFTYPE.DimensionInfo DimInfoBuf
  121.     GetDisplayInfoData_ FindDisplayInfo_(PrefDisplayID) AND $FFFFFFFF,&DimInfoBuf,SizeOf.DimensionInfo,#DTAG_DIMS,0
  122.     PrefDisplayLeft.w=((DimInfoBuf\TxtOScan\MaxX)-PrefDisplayWidth)/2
  123.     PrefDisplayTop.w=((DimInfoBuf\TxtOScan\MaxY)-PrefDisplayHeight)/2
  124.     *Scr._Screen=Peek.l(Addr Screen(0))
  125.     *ScrVP=ViewPort(0)
  126.     *ScrVP\DxOffset=PrefDisplayLeft,PrefDisplayTop
  127.     ScrollVPort_ *ScrVP
  128.     RethinkDisplay_
  129.     Menus Off
  130.     If *ScrVP\DHeight<>PrefDisplayHeight
  131.       Forbid_
  132.       *Scr\Height=PrefDisplayHeight ; Enforce y clipping
  133.       Permit_
  134.     EndIf
  135.     ScreenToFront_ *Scr
  136.     Function Return True
  137.   Else
  138.     Permit_
  139.     Function Return False
  140.   EndIf
  141. End Function
  142.  
  143. .Main
  144. ;**** NOT NECESSARY ****
  145. Pic$="5Ms.IFF"
  146. #Objects=1
  147. #UnQ=-1 ; Wether or not to unqueue the objects
  148. InitBank 0,PrefDisplayWidth*PrefDisplayHeight,$10000
  149. CludgeBitMap 0,PrefDisplayWidth,PrefDisplayHeight,8,Bank(0)
  150. InitPalette 0,256
  151. LoadBitMap 0,Pic$,0
  152. ;Make a chunky shape
  153. If MShape(0,64,64)=0 Then End
  154. MPlanar16ToShape 0,Bank(0),64,64,PrefDisplayWidth,PrefDisplayHeight
  155. MMakeCookie 0
  156. ;Make other shapes
  157. s=1
  158. For y=0 To 32 Step 32
  159.   For x=0 To 32 Step 32
  160.     If MShape(s,32,32)=0 Then End
  161.     MPlanar16ToShape s,Bank(0)+((PrefDisplayWidth/8)*y)+(x/8)+(64/8),32,32,PrefDisplayWidth,PrefDisplayHeight
  162.     MMakeCookie s
  163.     s+1
  164.   Next x
  165. Next y
  166. Free Bank 0
  167. .Table
  168. ;Set up movement table for moving objects
  169. Dim x.w(#Objects)
  170. Dim y.w(#Objects)
  171. Dim xdirection.b(#Objects)
  172. Dim ydirection.b(#Objects)
  173. Dim xdirectionswap.b(#Objects)
  174. Dim ydirectionswap.b(#Objects)
  175. For obj=1 To #Objects
  176.   x(obj)=Rnd(PrefDisplayWidth-48)+16
  177.   y(obj)=Rnd(PrefDisplayHeight-48)+16
  178.   Repeat
  179.     xdirection(obj)=Rnd(8)-4
  180.   Until xdirection(obj)<>0
  181.   Repeat
  182.     ydirection(obj)=Rnd(8)-4
  183.   Until ydirection(obj)<>0
  184.   xdirectionswap(obj)=-xdirection(obj)
  185.   ydirectionswap(obj)=-ydirection(obj)
  186. Next obj
  187. ;**** not necessary ****
  188.  
  189. .Prepare
  190. ;**** NECESSARY ****
  191. If InitDisplay{"Game"}=False Then Goto Finish
  192. ShowPalette 0
  193. *RP._RastPort=RastPort(0)
  194. Mc2pWindow 0,PrefDisplayWidth,PrefDisplayHeight ; Need this line in some form or other
  195. MCludgeBitmap 4,PrefDisplayWidth,PrefDisplayHeight*PrefDisplayBuffering,*RP\_BitMap\Planes
  196. ;**** necessary ****
  197.  
  198. ;Make some chunky buffers for source and background store
  199. If MBitmap(1,PrefDisplayWidth,PrefDisplayHeight)=0 Then End
  200. MAutoStencil On
  201. If MBitmap(0,PrefDisplayWidth,PrefDisplayHeight)=0 Then End
  202. ;Draw background pattern
  203. MUseShape 0
  204. MClsStencil 0
  205. For yy=0 To PrefDisplayHeight-64 Step 64
  206.   For xx=0 To PrefDisplayWidth-64 Step 64
  207.     MSBlock xx,yy
  208.   Next xx
  209. Next yy
  210. MUseBitmap 1
  211. MBlockScroll 0,0,PrefDisplayWidth,PrefDisplayHeight,0,0,0
  212. MUseBitmap 0
  213. ;Init queue and set blit mode for `put behind'
  214. MQSBlitCut On
  215. MSBlitCut On
  216. MQueue 0,#Objects
  217.  
  218. .Loop
  219. buf.b=0
  220. its.l=0
  221. cnt.b=0
  222. ResetTimer
  223. While Joyb(0)=0 AND Joyb(1)=0
  224.  
  225.   For obj=1 To #Objects
  226.     ;Move
  227.     x(obj)+xdirection(obj)
  228.     If x(obj)<4 OR x(obj)>PrefDisplayWidth-36 Then Exchange xdirection(obj),xdirectionswap(obj)
  229.     y(obj)+ydirection(obj)
  230.     If y(obj)<4 OR y(obj)>PrefDisplayHeight-36 Then Exchange ydirection(obj),ydirectionswap(obj)
  231.     ;Try changing this to a different type of blit. If it's not a Q-type blit, comment-out the unqueue line also
  232.     MQSBlit (obj MOD 4)+1,x(obj),y(obj) ; Stencil-cut blit and add to queue
  233.   Next obj
  234.  
  235.   ;Display
  236. ;**** NECESSARY ****
  237.   If IsAGA
  238.     Mc2p MBitmapPtr(0),PlanarBuf(buf)
  239.     ShowBitMap buf
  240.     If PrefDisplayBuffering>1
  241.       buf+1
  242.       If buf=PrefDisplayBuffering Then buf=0
  243.     EndIf
  244.   Else
  245.     MUseBitmap 4
  246.     If PrefDisplayBuffering>1
  247.       MBlockScroll 0,0,PrefDisplayWidth,PrefDisplayHeight,0,PrefDisplayHeight+(cnt*PrefDisplayHeight),0
  248.     Else
  249.       MBlockScroll 0,0,PrefDisplayWidth,PrefDisplayHeight,0,0,0
  250.     EndIf
  251.     MUseBitmap 0
  252.     *RP0._RastPort=RastPort(0)
  253.     *RP1._RastPort=RastPort(Min(PrefDisplayBuffering-1,1+cnt))
  254.     ClipBlit_ *RP1,0,0,*RP0,0,0,PrefDisplayWidth,PrefDisplayHeight,$C0
  255.     If PrefDisplayBuffering=3 Then cnt=1-cnt ; Toggle output buffer
  256.   EndIf
  257. ;**** necessary ****
  258.  
  259.   If #UnQ Then MUnQueue 0,1
  260.   MFlushQueue 0
  261.  
  262.   its+1
  263. Wend
  264.  
  265. ;Report
  266. t=Timer
  267. t=Max(t,1)
  268. its=Max(its,1)
  269. a.q=50.0/(t/its)
  270. WBenchToFront_
  271. FindScreen 1
  272. Window 2,16,16,300,40,0,"Test results",1,0
  273. WindowOutput 2
  274. NPrint a," frames per second"
  275. NPrint " "
  276. NPrint "Press mouse/joy button..."
  277. Repeat
  278. Until Joyb(0)<>0 OR Joyb(1)<>0
  279.  
  280. Finish:
  281. End
  282.  
  283.